﻿$(function() {
    $("#ddl_Provinces").change(function() {
        get_city2();
    });
    $("#ddl_Cities").change(function() {
        get_city3();
    });
    $("#ddl_Counties").change(function() {
        get_city4();
    });
    get_city2();
});

function get_city2() {
    var city1 = $("#ddl_Provinces").val();
    if (city1 != "") {
        $(".loading").html("loading...");
        $.ajax({
            type: "POST",
            url: "/member/shopping_address.aspx",
            data: "action=getcity&cityid=" + city1,
            success: function(msg) {
                if (msg != "") {
                    $("#ddl_Cities").html(msg);
                    $(".loading").html("");
                    get_city3();
                }
            }
        });
    }
}

function get_city3() {
    var city2 = $("#ddl_Cities").val();
    if (city2 != "") {
        $(".loading").html("loading...");
        $.ajax({
            type: "POST",
            url: "/member/shopping_address.aspx",
            data: "action=getcity&cityid=" + city2,
            success: function(msg) {
                if (msg != "") {
                    $("#ddl_Counties").html(msg);
                    $(".loading").html("");
                    get_city4();
                }
            }
        });
    }
}
function get_city4() {
    getCitiesValues(); //
}
function getCitiesValues() {
    if ($("#city1").val() != "") {
        $("#ddl_Provinces").each(function() {
            $("#city1").val($("#ddl_Provinces option:selected").text());
            $("#city2").val($("#ddl_Cities option:selected").text());
            $("#city3").val($("#ddl_Counties option:selected").text());
        });
    } else {
        $("#ddl_Provinces").each(function() {
            $("#city1").val("北京市");
            $("#city2").val("市辖区");
            $("#city3").val("东城区");
        });
    }
    //alert($("#ddl_Provinces option:selected").text() + "/" + $("#ddl_Cities option:selected").text() + "/" + $("#ddl_Counties option:selected").text());
}